#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/StochasticProcess.h>
#pragma unmanaged 
#include <ql\stochasticprocess.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Math;
#define HANDLE
#define ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IStochasticProcess1D
	public ref class CStochasticProcess1D  : 
            public CStochasticProcess,
            public Cephei::QL::IStochasticProcess1D
	{
	protected: 
		boost::shared_ptr<QuantLib::StochasticProcess1D>* _ppStochasticProcess1D;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::StochasticProcess1D>* _phStochasticProcess1D;
#endif
		Object^ _StochasticProcess1DOwner;     // reference to object that manages the storage for this object
	internal:
        CStochasticProcess1D (boost::shared_ptr<QuantLib::StochasticProcess1D>& childNative, Object^ owner);
        CStochasticProcess1D (QuantLib::StochasticProcess1D& childNative, Object^ owner);
        CStochasticProcess1D (CStochasticProcess1D^ copy);
        CStochasticProcess1D (PLATFORM::Type^ t);
#ifdef STRUCT
        CStochasticProcess1D (QuantLib::StochasticProcess1D childNative);
#endif       
#ifdef HANDLE
		CStochasticProcess1D (QuantLib::Handle<QuantLib::StochasticProcess1D>& childNative, Object^ owner);
		CStochasticProcess1D (QuantLib::Handle<QuantLib::StochasticProcess1D> childNative);
#endif
		virtual ~CStochasticProcess1D ();
		!CStochasticProcess1D ();

	internal:
		QuantLib::StochasticProcess1D& GetReference ();
		boost::shared_ptr<QuantLib::StochasticProcess1D>& GetShared ();
		QuantLib::StochasticProcess1D* GetPointer ();
        void SetStochasticProcess1D (boost::shared_ptr<QuantLib::StochasticProcess1D> native)
        {
            if (_ppStochasticProcess1D != NULL)
                delete _ppStochasticProcess1D;
            _ppStochasticProcess1D = new boost::shared_ptr<QuantLib::StochasticProcess1D> (native);
            SetStochasticProcess (boost::dynamic_pointer_cast<QuantLib::StochasticProcess> (*_ppStochasticProcess1D));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::StochasticProcess1D>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
		virtual Double Apply (Double x0, Double dx) ;
		virtual Double Diffusion (Double t, Double x) ;
		virtual Double Drift (Double t, Double x) ;
		virtual Double Evolve (Double t0, Double x0, Double dt, Double dw) ;
		virtual Double Expectation (Double t0, Double x0, Double dt) ;
		virtual Double StdDeviation (Double t0, Double x0, Double dt) ;
		virtual Double Variance (Double t0, Double x0, Double dt) ;
        property Double X0 
        {
		    virtual Double get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IStochasticProcess1D Vector interface
	ref class CStochasticProcess1DVector sealed : 
							    public Core::INativeVector<IStochasticProcess1D^>,
							    public Core::INativeVector<Core::Generic::ICoCell<IStochasticProcess1D^>^>
	{
	private:
#ifdef STRUCT
		std::vector<QuantLib::StochasticProcess1D>* _pVValue;
#endif        
		std::vector<boost::shared_ptr<QuantLib::StochasticProcess1D>>* _pVBoost;
#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::StochasticProcess1D>>* _pVHand;
#endif
		Object^ _owner;		// object reference to prevent GC of vector owner

	internal:
		CStochasticProcess1DVector ();
#ifdef STRUCT
		CStochasticProcess1DVector (std::vector<QuantLib::StochasticProcess1D>& vec, Object^ owner);
		CStochasticProcess1DVector (std::vector<QuantLib::StochasticProcess1D> vec);
#endif       
		CStochasticProcess1DVector (std::vector<boost::shared_ptr<QuantLib::StochasticProcess1D>>& vec, Object^ owner);
#ifdef HANDLE
		CStochasticProcess1DVector (std::vector<QuantLib::Handle<QuantLib::StochasticProcess1D>>& vec, Object^ owner);
#endif
		virtual ~CStochasticProcess1DVector ();
		!CStochasticProcess1DVector ();

    public:
		property int Count 
		{
			virtual int get ();
		}

		property IStochasticProcess1D^ default[int] 
		{
			virtual IStochasticProcess1D^ get (int index) = Core::INativeVector<IStochasticProcess1D^>::default::get;
			virtual void set (int index, IStochasticProcess1D^ value) = Core::INativeVector<IStochasticProcess1D^>::default::set;
		}

		//////////////////////////////////////////////////////////////////////////////////////////
		// Interface functions for cell vectors 
	public:
		property Core::Generic::ICoCell<Cephei::QL::IStochasticProcess1D^>^ CItem[int] 
		{
			virtual Core::Generic::ICoCell<IStochasticProcess1D^>^ get (int index) = Core::INativeVector<Core::Generic::ICoCell<IStochasticProcess1D^>^>::default::get;
			virtual void set (int index, Core::Generic::ICoCell<IStochasticProcess1D^>^ value) = Core::INativeVector<Core::Generic::ICoCell<IStochasticProcess1D^>^>::default::set;
		}
	internal:
#ifdef STRUCT    
		std::vector<QuantLib::StochasticProcess1D>& GetReference ();
#endif     
		std::vector<boost::shared_ptr<QuantLib::StochasticProcess1D>>& GetShared ();

#ifdef HANDLE
		std::vector<QuantLib::Handle<QuantLib::StochasticProcess1D>>& GetHandle ();
#endif
	public:
		virtual bool PrepareFeature (NativeFeature feature);
	};
    
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::IStochasticProcess1D^>::typeid)]
	[FactoryFor(Cephei::QL::IStochasticProcess1D::typeid)]
	[FactoryFor(Cephei::QL::IStochasticProcess1D_Factory::typeid)]
	public ref class CStochasticProcess1D_Factory sealed : public IStochasticProcess1D_Factory
	{
	public:
        /* <summary> Create a hybrid Vector of IStochasticProcess1D, with event notification of changes </summary> */
        virtual Cephei::Core::IVector<IStochasticProcess1D^>^ CreateVector();
        /* <summary> Create a hybrid Vector of ICell of IStochasticProcess1D, with event notification of changes </summary> */
        virtual Core::Generic::ICoCell<Cephei::Core::IVector<Core::Generic::ICoCell<IStochasticProcess1D^>^>^>^ CreateCellVector();
        virtual Cephei::Core::IVector<IStochasticProcess1D^>^ CreateVector(PLATFORM::Collections::Generic::IEnumerable<IStochasticProcess1D^>^ source);
        virtual Core::Generic::ICoCell<Cephei::Core::IVector<Core::Generic::ICoCell<IStochasticProcess1D^>^>^>^ CreateCellVector(PLATFORM::Collections::Generic::IEnumerable<Core::Generic::ICoCell<IStochasticProcess1D^>^>^ source);
		virtual Core::INativeVector<Cephei::QL::IStochasticProcess1D^>^ CreateNativeVector ()
		{
			return REFNEW CStochasticProcess1DVector ();
		}

        virtual Core::INativeMatrix<Cephei::QL::IStochasticProcess1D^>^ CreateNativeMatrix ()
		{
			return nullptr;
		}

        virtual Core::INativeCube<Cephei::QL::IStochasticProcess1D^>^ CreateNativeCube ()
		{
			return nullptr;
		}
    };
   
/*Cephei*/ } /*QL */}
